//_____________________________________
//  WAYPOINTS (scroll tracking)
//  change pic in footer for live map
//_____________________________________



// $(document).ready(function(){
//  //Footer Replacement
//         $('#activateMap').waypoint(function() {
//          $('#activateMap').replaceWith('<iframe width='+ $(window).width() +' height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://www.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=synectic+software+%26+services+gmbh,+Wei%C3%9Fenseer+Weg+110,+Berlin,+Germany&amp;aq=0&amp;oq=synectic&amp;sll=52.527371,13.479309&amp;sspn=0.001412,0.003066&amp;ie=UTF8&amp;hq=synectic+software+%26+services+gmbh,&amp;hnear=Wei%C3%9Fenseer+Weg+110,+10367+Berlin,+Germany&amp;t=m&amp;ll=52.529394,13.483186&amp;spn=0.004569,0.025749&amp;z=16&amp;iwloc=A&amp;output=embed"></iframe>');
//    });  
//    $('#activateMap').click(function() {
//          $('#activateMap').replaceWith('<iframe width='+ $(window).width() +' height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://www.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=synectic+software+%26+services+gmbh,+Wei%C3%9Fenseer+Weg+110,+Berlin,+Germany&amp;aq=0&amp;oq=synectic&amp;sll=52.527371,13.479309&amp;sspn=0.001412,0.003066&amp;ie=UTF8&amp;hq=synectic+software+%26+services+gmbh,&amp;hnear=Wei%C3%9Fenseer+Weg+110,+10367+Berlin,+Germany&amp;t=m&amp;ll=52.529394,13.483186&amp;spn=0.004569,0.025749&amp;z=16&amp;iwloc=A&amp;output=embed"></iframe>');
//    });  
//  //ToolTip Function hide
//  setTimeout(function(){ $(".hint").removeClass('hint  hint--bottom'); }, 15000);
//  //$(".hint  .hint--bottom").delay(10000).hide("slow");  
// });    


//_____________________________________
//      SIDR config
//_____________________________________

$(document).ready(function() {
    $('#responsive-menu-button').sidr();
    var status = true; //you can always check if menu is open or closed via status var (true = menu is hidden)
    var i = 0; // i is the initializer for puls animation of the menu button
    $('#responsive-menu-button').click(function() {
        if (status === true) {
            $('#responsive-menu-button').sidr('open', 'sidr-main', status = false); //opens the menu
            console.log(status); //print out status


            $('<div id="overlay" class="dark-overlay"></div>').appendTo("body"); // append a div
            $('body').css('overflow', 'hidden');

            $('#overlay').click(function() {
                $('#overlay').remove();
                $('body').css('overflow', 'auto');
                $.sidr('close', 'sidr-main', status = true);
                //removes overlay container after clicking 
                console.log(status); //print out status
            });

        } else {
            $('#responsive-menu-button').sidr('close', 'sidr-main', status = true); //close menu 
            console.log(status); //print out status

        }
    });


    for (i; i <= 4; i++) {
        $('.primary-toggle').animate({
            opacity: 0.25
        }, 1500);
        //console.log('what');
        $('.primary-toggle').animate({
            opacity: 1
        }, 1500);

    }




});



//_____________________________________
//    DROPDOWN config
//_____________________________________



$(document).ready(function() {

    function DropDown(el) {
        this.dd = el;
        this.placeholder = this.dd.children('span');
        this.placeholderTXT = this.dd.children('span').text();
        this.opts = this.dd.find('ul.dropdown > li');
        this.val = '';
        this.index = -1;
        this.initEvents();
    }
    DropDown.prototype = {
        initEvents: function() {
            var obj = this;

            obj.dd.on('click', function(event) {
                $(this).toggleClass('active');
                return false;
            });

            obj.opts.on('click', function() {
                var opt = $(this);
                obj.val = opt.text();
                obj.index = opt.index();
                obj.placeholder.text(obj.placeholderTXT + ": " + obj.val);
            });
        },
        getValue: function() {
            return this.val;
        },
        getIndex: function() {
            return this.index;
        }
    }

    function dropThatDown(ddID) {
        //ddID is the DropDown Identification for supporting mulitple DropDowns
        var dd = new DropDown(ddID);

        $('.dropdown').mouseleave(function() {
            // all dropdowns
            $('.wrapper-dropdown-1').removeClass('active');

        });


        $(document).click(function() {
            // all dropdowns
            $('.wrapper-dropdown-1').removeClass('active');

        });


    }
    //Generates an Arrayy to List all Dropdowns in this Page

    var ddFx = function() {

        ddIDs = []; // Array for ddIDs
        $('body').find(".wrapper-dropdown-1").each(function() {
            ddIDs.push($('#' + this.id)); //collects Ids and push's them in to the array
        });
        //console.log(ddIDs); //debug
        var i;
        var l = (ddIDs.length - 1);
        for (i = 0; i <= l; i++) {
            dropThatDown(ddIDs[i]); // for every collected ID call function with collected ID as parameter
        }
    }
    ddFx(); // call function to start passing IDs to dropThatDown

});


//_____________________________________
//      ISOTOPE config
//_____________________________________

function teamPicsFit() {
    $('#teamPics').isotope({
        layoutMode: 'fitRows'
    });
};
$(window).load(function() {
    //$(".loader").hide();
    //$("#teamPics").show();
    $(".loader").fadeOut('slow');
    $("#teamPics").fadeIn('slow');
    teamPicsFit();
});
teamPicsFit();



$('.item').click(function() {
    //  $('.item').removeClass('item-selected');


    if ($(this).hasClass('item-selected')) {
        $(this).removeClass('item-selected');
    } else {
        $('.item').removeClass('item-selected');
        $(this).addClass('item-selected');
    }
    teamPicsFit();
});



// cache container
var $container = $('#teamPics');

$container.isotope({

});
//Filter
$(document).ready(function() {
    $('#filters a').click(function() {
        var selector = $(this).attr('data-filter');
        $container.isotope({
            filter: selector
        });
        // $('.wrapper-dropdown-1').removeClass('active');
        // return false;
    });
});

// //_____________________________________
// //      Course Content
// //____________WORKS____________________
// $(document).ready(function() {

//   $('.fx-showContent').click(function(e){
//     e.preventDefault();
//     currentEvent = $(this);
//     if(currentEvent.hasClass('unfolded')){
//       $(this).text('zu den Inhalten');
//       $(this).parent().siblings('.courseContent').slideUp(600 ,function(){
//         // $('#schulung').isotope( 'reLayout');
//         currentEvent.removeClass('unfolded');
//       });

//     }else{
//         $(this).text('Inhalt schließen');
//         $(this).parent().siblings('.courseContent').slideDown(600 ,function(){
//           // $('#schulung').isotope( 'reLayout');
//           currentEvent.addClass('unfolded');
//         });
//     }
//   });
// });



// //_____________________________________
// //      Course Content
// //____________Experiment_______________

$(document).ready(function() {

  $('.fx-showContent').click(function(e) {
      e.preventDefault();
      currentEvent = $(this);
      wrap = $('.fx-courseContentWrapper');
      isotopeItem = $('.fx-course');
      if (currentEvent.hasClass('open')) {
          $(this).text('zu den Inhalten');

          $(this).parents().find(wrap).height(+600);


          currentEvent.removeClass('open');
      } else {
          $(this).text('Inhalt schließen');


          $(this).parents().find(wrap).height(+200);


          currentEvent.addClass('open');
      }
  });
});


//_____________________________________
//      MODAL config
//_____________________________________


// $(document).ready(function() {

//   var mod;// modal itself
//   var modOpen;//modal open Button
//   var modClose;//modal close Button

//   var modalInit = function (modalID) {

//         var mod = (modalID); //pass ID to function
//         var modOpen = (mod + 'BttnOpen'); // generate the Open button ID
//         var modClose = (mod + 'BttnClose'); // generate the Close button ID

//         $(mod).easyModal({ // general settings
//           top: 100,
//           autoOpen: false,
//           overlayOpacity: 0.3,
//           overlayColor: "#333",
//           overlayClose: true,
//           closeOnEscape: true
//         });
//         $(modOpen).click(function(e){ //click on OPenButton ID to open
//             $(mod).trigger('openModal'); //open method from Plugin
//             e.preventDefault();
//         });
//         $(modClose).click(function(e){  //click on OPenButton ID to close
//             $(mod).trigger('closeModal'); //clsoe method from Plugin
//             e.preventDefault();
//         });

//   }
//   //find all MODAL IDs in the container with the ID modals

//   var modalIDs;

//   var modalIDsFx = function(){

//       modalIDs = [];// Array for ModalIDs
//       $("#modals").find(".modal").each(function(){ 
//         modalIDs.push('#' + this.id); //collects Ids and push's them in to the array
//       });
//       //console.log(modalIDs); //debug
//       var i;
//       var l = (modalIDs.length - 1);  
//       for( i=0; i <= l; i++){
//          modalInit(modalIDs[i]);// for every collected ID call function with collected ID as parameter
//       } 
//         //Clean mess of lean overlay
//           var ol = $('.lean-overlay').length;
//           console.log(ol);
//           if(ol > 1){
//             $('.lean-overlay').remove();
//           }
//   }
//   modalIDsFx();// call function to start passing IDs to modalInit




// });
